package hospital.user.api;

import hospital.model.user.Patient;
import hospital.result.Result;
import hospital.user.service.PatientService;
import hospital.utils.AuthContextHolder;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author
 * @description:
 */
//就诊人管理接口
@Api("就诊人管理接口")
@RestController
@RequestMapping("/api/user/patient")
public class PatientApiController {
    @Autowired
    private PatientService patientService;
    /**
     * @Author yang
     * @Description //TODO 通过userid获取就诊人列表
     * @Param
     * @return
     **/
    @GetMapping("auth/findAll")
    public Result findAll(HttpServletRequest request){
        //获取到用户的userId
        Long userId = AuthContextHolder.getUserId(request);
        List<Patient> list=patientService.findAllByUserId(userId);
        return Result.ok(list);
    }

    /**
     * @Author yang
     * @Description //TODO 通过就诊人的id获取，就诊人的信息
     * @Param
     * @return
     **/
    @GetMapping("auth/getPatientInfo/{id}")
    public Result getPatientInfo(@PathVariable Long id){
        Patient patient=patientService.getPatientInfo(id);
        return Result.ok(patient);
    }

    /**
     * @Author yang
     * @Description //TODO //保存就诊人信息
     * @Param
     * @return
     **/
    @PostMapping("auth/savePatient")
    public Result savePatient(@RequestBody Patient patient,HttpServletRequest request){
        Long userId = AuthContextHolder.getUserId(request);
        patient.setUserId(userId);
        patientService.save(patient);
        return Result.ok();
    }

    /**
     * @Author yang
     * @Description //TODO//修改就诊人信息
     * @Param
     * @return
     **/
    @PostMapping("auth/updatePatient")
    public Result updatePatient(@RequestBody Patient patient ){
        patientService.updateById(patient);
        return Result.ok();
    }
    /**
     * @Author yang
     * @Description //TODO //删除就诊人信息
     * @Param
     * @return
     **/
    @DeleteMapping("auth/removePatient/{id}")
    public Result removePatient(@PathVariable Long id){
        patientService.removeById(id);
        return Result.ok();
    }

    /**
     * @Author yang
     * @Description //TODO 根据就诊人id获取就诊人信息
     * @Param
     * @return
     **/
    @GetMapping("inner/get/{id}")
    public Patient getPatientOrder(@PathVariable("id") Long id){
        return patientService.getPatientOrder(id);
    }
}
